package com.ljh.server.handler;

import com.ljh.message.GroupMembersRequestMessage;
import com.ljh.message.GroupMembersResponseMessage;
import com.ljh.server.session.GroupSessionFactory;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.Set;

/**
 * @author: Themberfue
 * @date: 2025/5/29 22:48
 * @description:
 */
@ChannelHandler.Sharable
public class GroupMembersRequestHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupMembersRequestMessage msg) throws Exception {
        String groupName = msg.getGroupName();

        Set<String> members = GroupSessionFactory.getGroupSession().getMembers(groupName);

        ctx.writeAndFlush(new GroupMembersResponseMessage(members));
    }
}
